<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
    <div class="content">
        <div class="panel panel-default panel-intro">

            <div class="panel-body">
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane fade active in" id="one">
                        <div class="widget-body no-padding">

                            <div class="bootstrap-table">
                                <div class="commonsearch-table ">
                                    <fieldset>
                                        <div class="row">

<!--                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">-->
<!--                                                <label for="createtime" class="control-label col-xs-4">录单时间</label>-->
<!--                                                <div class="col-xs-8">-->
<!--                                                    <input type="text" class="form-control datetimepicker" name="createtime" value="{:date('Y-m-d H:i:s',$row['createtime'])}" placeholder="录单时间" id="createtime" data-index="2">-->
<!--                                                </div>-->
<!--                                            </div>-->
                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">
                                                <label for="deliverytime" class="control-label col-xs-4">交货日期</label>
                                                <div class="col-xs-8">
                                                    <input type="text" class="form-control datetimepicker" name="deliverytime" value="{:date('Y-m-d H:i:s',$row['deliverytime'])}" placeholder="录单时间" id="deliverytime" data-index="2" disabled>
                                                </div>
                                            </div>

                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">
                                                <label for="c-storehouse_id" class="control-label col-xs-4">出库仓库</label>
                                                <div class="col-xs-8">
                                                    <input id="c-storehouse_id" data-rule="required" data-source="data/storehouse/index" data-field="name" class="form-control selectpage" name="storehouse_id" type="text" value="{$row['storehouse_id']}" disabled>
                                                </div>
                                            </div>
                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">
                                                <label for="c-sales_type_id" class="control-label col-xs-4">销售类型</label>
                                                <div class="col-xs-8">
                                                    <input id="c-sales_type_id" data-rule="required" data-source="sales/type/index" data-field="name" class="form-control selectpage" name="sales_type_id" type="text" value="{$row['sales_type_id']}" disabled>
                                                </div>
                                            </div>
                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">
                                                <label for="contacts" class="control-label col-xs-4">销售单号</label>
                                                <div class="col-xs-8">
                                                    <input type="text" class="form-control" data-rule="required" name="sales_number" value="{$row['sales_number']}" placeholder="销售单号" id="sales_number" data-index="14" disabled>
                                                </div>
                                            </div>
                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">
                                                <label for="company" class="control-label col-xs-4">税点</label>
                                                <div class="col-xs-8">
                                                    <input type="text" class="form-control " name="tax" value="{$row['tax']}" placeholder="税点" id="shuifei" data-index="7" disabled>
                                                </div>
                                            </div>
                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">
                                                <label for="operator" class="control-label col-xs-4">经手人</label>
                                                <div class="col-xs-8">
                                                    <input type="text" class="form-control" name="operator"  placeholder="经手人" id="operator" data-index="6" value="{$row['operator']}" disabled>
                                                </div>
                                            </div>
                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">
                                                <label for="company" class="control-label col-xs-4">部门单位</label>
                                                <div class="col-xs-8">
                                                    <input type="text" class="form-control" name="company"  placeholder="部门单位" id="company" data-index="7" value="{$row['company']}" disabled>
                                                </div>
                                            </div>
<!--                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">-->
<!--                                                <label for="explain" class="control-label col-xs-4">说明</label>-->
<!--                                                <div class="col-xs-8">-->
<!--                                                    <input type="text" class="form-control" name="explain" value="" placeholder="说明" id="explain" data-index="13">-->
<!--                                                </div>-->
<!--                                            </div>-->
<!--                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3"><label for="abstract" class="control-label col-xs-4">摘要</label><div class="col-xs-8">-->
<!--                                                <input type="text" class="form-control" name="abstract" value="{$row['company']}" placeholder="摘要" id="abstract" data-index="14">-->
<!--                                            </div>-->
<!--                                            </div>-->
                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">
                                                <label for="c-customer_id" class="control-label col-xs-4">客户</label>
                                                <div class="col-xs-8">
                                                    <input id="c-customer_id" data-rule="required" data-source="customer/customer/index" data-field="company" class="form-control selectpage" name="customer_id" type="text" value="{$row['customer_id']}" disabled>
                                                </div>
                                            </div>
                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">
                                                <label for="contacts" class="control-label col-xs-4">联系人</label>
                                                <div class="col-xs-8">
                                                    <input type="text" class="form-control" name="contacts" value="{$row['contacts']}" placeholder="联系人" id="contacts" data-index="14" disabled>
                                                </div>
                                            </div>
                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">
                                                <label for="address" class="control-label col-xs-4">收货地址</label>
                                                <div class="col-xs-8">
                                                    <input type="text" class="form-control" name="address" value="{$row['address']}" placeholder="收货地址" id="address" data-index="14" disabled>
                                                </div>
                                            </div>
                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">
                                                <label for="mobile" class="control-label col-xs-4">手机</label>
                                                <div class="col-xs-8">
                                                    <input type="text" class="form-control" name="mobile" value="{$row['mobile']}" placeholder="手机" id="mobile" data-index="14" disabled>
                                                </div>
                                            </div>

                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">
                                                <label for="default_mobile" class="control-label col-xs-4">默认电话</label>
                                                <div class="col-xs-8">
                                                    <input type="text" class="form-control" name="default_mobile" value=""  id="default_mobile" data-index="14"disabled>
                                                </div>
                                            </div>
                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">
                                                <label for="default_address" class="control-label col-xs-4">默认地址</label>
                                                <div class="col-xs-8">
                                                    <input type="text" class="form-control" name="default_address" value="" id="default_address" data-index="14"disabled>
                                                </div>
                                            </div>
                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">
                                                <label for="default_contacts" class="control-label col-xs-4">默认联系人</label>
                                                <div class="col-xs-8">
                                                    <input type="text" class="form-control" name="default_contacts" value=""  id="default_contacts" data-index="14"disabled>
                                                </div>
                                            </div>
<!--                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">-->
<!--                                                <label for="default_logistics" class="control-label col-xs-4">常见物流</label>-->
<!--                                                <div class="col-xs-8">-->
<!--                                                    <input type="text" class="form-control" name="default_logistics" value=""  id="default_logistics" data-index="14" disabled>-->
<!--                                                </div>-->
<!--                                            </div>-->

                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">
                                                <label for="explain" class="control-label col-xs-4">说明</label>
                                                <div class="col-xs-8">
                                                    <input type="text" class="form-control" name="explain" value="{$row.explain}"  id="explain" data-index="14" disabled>
                                                </div>
                                            </div>
<!--                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">-->
<!--                                                <label for="default_logistics" class="control-label col-xs-4">运费</label>-->
<!--                                                <div class="col-xs-8">-->
<!--                                                    <input type="text" class="form-control" name="allfare" value="{$row.allfare}"  id="allfare" data-index="14" disabled>-->
<!--                                                </div>-->
<!--                                            </div>-->

                                        </div>
                                </fieldset>
                                </div>
                            </div>



                            <div class="fixed-table-toolbar">
                                <div class="bs-bars pull-left"><div id="toolbar" class="toolbar" style="position: relative;">
                                    <a href="javascript:;" class="btn btn-success btn-add " title="添加"><i class="fa fa-plus"></i> 添加</a><span style="color: #b86607">如销售价格大于成本价，该订单不会计入审核流程。</span>
                                </div>
                            </div>

                        <div class="columns-right pull-right" style="margin-top:10px;margin-bottom:10px;"></div>
                            <table id="table" class="table table-striped table-bordered table-hover table-nowrap"  data-operate-edit="1" data-operate-del="1" width="100%">
                                <thead>
                                <tr>
                                    <th style="text-align: center; vertical-align: middle; " data-field="id"><div class="form-group ">Id</div></th>
                                    <!--                                <th style="text-align: center; vertical-align: middle; " data-field="createtime"><div class="th-inner ">出库仓库</div></th>-->
                                    <th style="text-align: center; vertical-align: middle; " ><div class="th-inner ">商品编号</div></th>
                                    <th style="text-align: center; vertical-align: middle; " data-field="number"><div class="th-inner ">商品名称</div></th>
                                    <th style="text-align: center; vertical-align: middle; " data-field="status"><div class="th-inner ">产地</div></th>
                                    <th style="text-align: center; vertical-align: middle; " data-field="supplier_id"><div class="th-inner ">规格</div></th>
                                    <th style="text-align: center; vertical-align: middle; " data-field="operator"><div class="th-inner ">账面库存</div></th>
                                    <th style="text-align: center; vertical-align: middle; " data-field="company"><div class="th-inner ">虚拟库存</div></th>
                                    <th style="text-align: center; vertical-align: middle; " data-field="order_goods_total"><div class="th-inner ">销售数量</div><div class="fht-cell"></div></th>
                                    <th style="text-align: center; vertical-align: middle; " data-field="order_goods_total"><div class="th-inner ">出库数量</div><div class="fht-cell"></div></th>
                                    <th style="text-align: center; vertical-align: middle; " data-field="arrival_total"><div class="th-inner ">销售单位</div><div class="fht-cell"></div></th>
                                    <th style="text-align: center; vertical-align: middle; " data-field="order_price"><div class="th-inner ">销售单价</div><div class="fht-cell"></div></th>
                                    <th style="text-align: center; vertical-align: middle; " data-field="order_price"><div class="th-inner ">销售金额</div><div class="fht-cell"></div></th>
                                    <th style="text-align: center; vertical-align: middle; " data-field="arrival_price"><div class="th-inner ">税点</div><div class="fht-cell"></div></th>
                                    <th style="text-align: center; vertical-align: middle; " data-field="paid_in_price"><div class="th-inner ">含税单价</div><div class="fht-cell"></div></th>
                                    <th style="text-align: center; vertical-align: middle; " data-field="paid_in_price"><div class="th-inner ">税额</div><div class="fht-cell"></div></th>
                                    <!--                                <th style="text-align: center; vertical-align: middle; " data-field="explain"><div class="th-inner ">所有运费</div><div class="fht-cell"></div></th>-->
                                    <!--                                <th style="text-align: center; vertical-align: middle; " data-field="explain"><div class="th-inner ">单件运费</div><div class="fht-cell"></div></th>-->
                                    <th style="text-align: center; vertical-align: middle; " data-field="explain"><div class="th-inner ">合计</div><div class="fht-cell"></div></th>
                                    <th style="text-align: center; vertical-align: middle; " data-field="operate"><div class="th-inner ">备注</div><div class="fht-cell"></div></th>
                                    <th style="text-align: center; vertical-align: middle; " data-field="operate"><div class="th-inner ">操作</div><div class="fht-cell"></div></th>
                                </tr>
                                </thead>
                                <tbody data-listidx="0" class="connnn" >
                                {volist name="rows" id="vo"}
                                        <tr data-index="0"  {if condition="$vo['status'] == 5"} style="background-color: red" {elseif condition="$vo['status'] == 6"/}style="background-color: #fff700" {else /}
                                        {if condition="$vo.sale_num >0 && $vo.sale_num < $vo.goods_num"}style="background-color: #0ddc82"{else /}{/if}
                                        {/if}>
                                            <td class="bs-checkbox ">{$vo.id}</td>
                                            <td style="text-align: center; vertical-align: middle; "><a target="_blank" href="#">{$vo.number}</td>
                                            <td style="text-align: center; vertical-align: middle; ">{$vo.title}</td>
                                            <td style="text-align: center; vertical-align: middle; ">{$vo.place_origin}</td>
                                            <td style="text-align: center; vertical-align: middle; " >{$vo.specs}</td>
                                            <td style="text-align: center; vertical-align: middle;{if condition="$vo.stock == 0"}color: red{else /}{/if} " >{$vo.stock}</td>
                                            <td style="text-align: center; vertical-align: middle;{if condition="$vo.stock == 0"}color: red{else /}{/if} ">{$vo.xstock}</td>
                                            <td style="text-align: center; vertical-align: middle; " class="goods_num">{$vo.goods_num}</td>
                                            <td style="text-align: center; vertical-align: middle; color: red" class="goods_num" >{$vo.sale_num}</td>
                                            <td style="text-align: center; vertical-align: middle; ">{$vo.unit}</td>
                                            <td style="text-align: center; vertical-align: middle; " class="">
                                                <input type="text" class="form-control" style="display: none" value="{$vo.sale_price}" name="row[{$vo.goods_id}][sale_price]" onkeyup="checkInputIntFloat(this);">
                                                <span class="price " data-jxs_price="{$vo.jxs_price}"  {if condition="$vo.jxs_price == 0"}style="background:#63580b4a"
                                                    {elseif condition="$vo.jxs_price < $vo['sale_price']"/} style="color:#0cde91bf;"
                                                    {elseif condition="$vo.jxs_price > $vo['sale_price']"/} style="color:red;"
                                                    {else /}
                                                    {/if}>{$vo.sale_price}</span>
                                            </td>
                                            <td style="text-align: center; vertical-align: middle; " class="buy_price">{$vo.buy_price}</td>
                                            <td style="text-align: center; vertical-align: middle; " >{$vo.tax}</td>
                                            <td style="text-align: center; vertical-align: middle; " >{$vo.ht_price}</td>
                                            <td style="text-align: center; vertical-align: middle; " class="tax_all">{$vo.tax_all}</td>
                                            <td style="text-align: center; vertical-align: middle; " class="ht_price">{$vo.sfhj}</td>
                                            <td style="text-align: center; vertical-align: middle;min-width: 100px;
                                                        white-space: nowrap;
                                                        text-overflow:ellipsis;
                                                        overflow:hidden;
                                                        max-width: 120px" class="remark">{$vo.remark}</td>
                                            <td style="text-align: center; vertical-align: middle; " >
                                                <a href="javascript:;" class="btn btn-xs btn-success btn-caigou" data-goods_id="{$vo.goods_id}" title="采购" data-table-id="table" data-field-index="13" data-row-index="0" data-button-index="0"><i class="fa fa-shopping-basket"></i></a>
                                            </td>
                                        </tr>
                                {/volist}
                                </tbody>

                                <tbody class="tbfoot" data-listidx="0" style="display: ">
                                    <td style="text-align: center; vertical-align: middle; ">合计</td>
                                    <td style="text-align: center; vertical-align: middle; "></td>
                                    <td style="text-align: center; vertical-align: middle; "></td>
                                    <td style="text-align: center; vertical-align: middle; "></td>
                                    <td style="text-align: center; vertical-align: middle; "></td>
                                    <td style="text-align: center; vertical-align: middle; " class="zstock">0</td>
                                    <td style="text-align: center; vertical-align: middle; " class="xstock">0</td>
                                    <td style="text-align: center; vertical-align: middle; " class="allnum">0</td>
                                    <td style="text-align: center; vertical-align: middle; "></td>
                                    <td style="text-align: center; vertical-align: middle; "></td>
                                    <td style="text-align: center; vertical-align: middle; " ></td>
                                    <td style="text-align: center; vertical-align: middle; "class="alprice">0</td>
                                    <td style="text-align: center; vertical-align: middle; "></td>
                                    <td style="text-align: center; vertical-align: middle; "></td>
                                    <td style="text-align: center; vertical-align: middle; "class="alltax">0</td>
                                    <td style="text-align: center; vertical-align: middle; "class="all_cost">0</td>
                                    <td style="text-align: center; vertical-align: middle; "></td>
                                    <td style="text-align: center; vertical-align: middle; "></td>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>



    <div style="text-align: center">
        <span >表格红色代表已经取消,黄色代表转为直发</span>
    </div>

    {if condition="$auth->check('sales/slip/examine') && $row.status == 1 "}
        <input type="hidden" name="status" value="1">
        <div class="form-group layer-footer">
            <label class="control-label col-xs-12 col-sm-2"></label>
            <div class="col-xs-12 col-sm-8">
                <button type="submit" class="btn btn-success btn-embossed subpurchase">{:__('OK')}</button>
                <button type="submit" class="btn btn-default btn-embossed reset">驳回</button>
            </div>
        </div>
    {else /}

    {/if}
    {if condition="$row.status == 7 "}

    {else /}

    {/if}
</form>
{if condition="$row.status == 2 "}
<div class="form-group layer-footer">
    <label class="control-label col-xs-3 col-sm-2"></label>
    <div class="col-xs-12 col-sm-3">
        <button type="submit" class="btn btn-danger btn-embossed cancelbill {:$auth->check('sales/slip/cancelbill')?'':'hide'}">{:__('单据红冲')}</button>
    </div>
</div>
{else /}

{/if}
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
<script>
    $('thead').on('mousedown','th',function (e) {
        if(3 == e.which){
            var index3 = $(this).index()
            console.log(index3)
            index= $("thead").find('th').index(this);
            $('thead').find('th').eq(index).remove()
            $('tbody').find('tr').each(function () {
                $(this).find('td').eq(index).remove()
            })
            $('tbody').find('th').eq(index).remove()

            console.log(index)
            $(document).bind("contextmenu",function(e){
                return false;
            })
        }
    })
    $('body').on('click','.btn-caigou',function () {
        var gid = $(this).data('goods_id')
        var url = "{$turl}"
        layer.open({
            type: 2, // 1-在content中写html代码， 2-在content中写src路径
            area: ['50%', '90%'],
            title: "采购商品",
            content: url+'/goods/goods/addpgoods?ids='+gid,
            // content: Config.this_url+'/purchase/requisition',
        })
    })
</script>
<script>
    $('body').on('mouseenter','.remark',function () {
        if (this.offsetWidth < this.scrollWidth) {
            var that = this;
            var text = $(this).text();
            layer.tips(text, that,{
                tips: 1,
                time: 2000         //设置显示时间
            });
        }
    })
    $('body').on('mouseenter','.price',function () {
        var that = this;
        var text = $(this).data('jxs_price');
        layer.tips(text, that,{
            tips: 1,
            time: 500         //设置显示时间
        });
    })



    $('.subpurchase').click(function () {
        $("input[name='status']").val(2)
    })
    $('.reset').click(function () {
        $("input[name='status']").val(6)
    })






    getcustomer()
    function getcustomer() {
        var cid = "{$row.customer_id}"
        if(cid == ''){
            return  false;
        }
        customer_id = cid;
        var url = "{$turl}"+'/customer/customer/detail?ids='+cid
        $.post(url,{},function (res) {
            $('#default_mobile').val(res.mobile)
            $('#default_address').val(res.address)
            $('#default_contacts').val(res.nickname)
        })
    }

    count()
    function count() {
        if($(".connnn > tr").length == 0){
            $('.tbfoot').attr('style','display:none')
            return false;
        }

        var alprice = 0;//销售金额
        var allnum = 0;//销售数量
        var alltax = 0;//税额
        var fare = 0;//税费合计
        var all_cost = 0;//运运费合计


        $('.connnn').find("tr").each(function(){
            var goods_num = $(this).find('.goods_num').html()*1;
            var buy_price = $(this).find('.buy_price').html()*1;
            var tax_all = $(this).find('.tax_all').html()*1;
            // var all_fare = $(this).find('.all_fare').html()*1;
            var ht_price = $(this).find('.ht_price').html()*1;
            allnum= allnum+goods_num
            alprice= buy_price+alprice
            alltax= alltax+tax_all
            // fare= fare+all_fare
            all_cost= all_cost+ht_price

        });
        $('.alprice').html(alprice.toFixed(2))
        $('.allnum').html(allnum)
        $('.alltax').html(alltax.toFixed(2))
        // $('.fare').html(fare)
        $('.all_cost').html(all_cost.toFixed(2))
    }



</script>
{include file='common/adapt' /}